package com.jason.www.activity;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Environment;
import android.util.Log;
import android.view.ViewTreeObserver;
import android.widget.ImageView;

import com.jason.www.R;
import com.jason.www.base.BaseActivity;
import com.jason.www.utils.DisplayUtils;

import java.io.File;
import java.io.FileOutputStream;

import butterknife.BindView;

public class SplashActivity extends BaseActivity {
    @BindView(R.id.imageview_splash)
    ImageView imageView;

    @Override
    protected void initView() {
        super.initView();
        Log.d("SplashActivity", "DisplayUtils.realWidth():" + DisplayUtils.realWidth());
        Log.d("SplashActivity", "DisplayUtils.realHeight():" + DisplayUtils.realHeight());
        getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
//                screenShot(SplashActivity.this);
            }
        });
        getWindow().getDecorView().postDelayed(new Runnable() {
            @Override
            public void run() {
                gotoPage(MainActivity.class);
                finish();
            }
        }, 1000);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_splash;
    }

    /**
     * 屏幕截图
     */
    public static void screenShot(Activity activity) {
        String filepath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.separator + System.currentTimeMillis() + ".jpg";
        Bitmap bitmap = null;
        try {
            //截图
            activity.getWindow().getDecorView().setDrawingCacheEnabled(true);
            bitmap = activity.getWindow().getDecorView().getDrawingCache();
            //保存图片
            FileOutputStream fos = new FileOutputStream(filepath);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        } catch (Exception e) {
            Log.d("SplashActivity", e.getMessage());
        }
    }
}